package cn.com.self.apis.escrow.controller;


import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.com.self.apis.portal.util.ICustomPage;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.self.apis.escrow.entity.EscrowMarginInfo;
import cn.com.self.apis.escrow.service.IEscrowMarginInfoService;
import cn.com.self.apis.util.CopyUtils;
import cn.com.selfsoft.smartcity.commons.http.DataItem;
import cn.com.selfsoft.smartcity.commons.http.DataPage;
import cn.com.selfsoft.smartcity.commons.http.ResultModel;
import cn.com.selfsoft.smartcity.commons.util.ParameterUtil;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liangwt
 * @since 2020-05-29
 */
@Controller
@RequestMapping("/escrowMarginInfo")
@Api(tags = "托管保证金明细类")
public class EscrowMarginInfoController {
	@Autowired
	private IEscrowMarginInfoService escrowMarginInfoService;
	/**新增托管保证金明细
     * @Description //TODO
     * @return
     **/
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增托管信息新增托管保证金明细")
    public ResponseEntity create(@RequestBody EscrowMarginInfo entity, HttpServletRequest request){
        entity.setCreateDate(new Date());
        entity.setUpdateDate(new Date());
    	EscrowMarginInfo create = escrowMarginInfoService.create(entity);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(create));
    }


    /**分页获取托管保证金明细列表
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "分页获取托管保证金明细列表")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity getEscrowMarginInfoPage(HttpServletRequest request, Pageable page){
    	Map<String, Object> queryParams = ParameterUtil.HumpToUnderline(request.getParameterMap(), "mark", "size", "page","sort","access_token");
        ICustomPage<EscrowMarginInfo> pageData = this.escrowMarginInfoService.page(queryParams, page);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(pageData));

    }

    /**获取托管保证金明细
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "获取托管保证金明细")
    @RequestMapping(value = {"/load/{id}"}, method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity loadEscrowMarginInfo(@PathVariable("id") String id,HttpServletRequest request) {
    	EscrowMarginInfo escrowMarginInfo = this.escrowMarginInfoService.load(id);
    	return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(new DataItem(escrowMarginInfo)));

    }


    /**修改托管保证金明细信息
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "修改托管保证金明细信息")
    @RequestMapping(value = {"/update/{id}"}, method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity update(@PathVariable("id") String id, @RequestBody EscrowMarginInfo entity, HttpServletRequest request) {
    	EscrowMarginInfo escrowMarginInfo = this.escrowMarginInfoService.load(id);
    	CopyUtils.copyProperties(entity, escrowMarginInfo);
        escrowMarginInfo.setUpdateDate(new Date());
    	EscrowMarginInfo update = this.escrowMarginInfoService.update(escrowMarginInfo);
    	return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(new DataItem(update)));

    }


    /**删除托管保证金明细信息
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "删除托管保证金明细信息")
    @ResponseBody
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public ResponseEntity deletes(@PathVariable("id") String id){
    	this.escrowMarginInfoService.delete(id);
    	return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(1));
    }
}

